package cn.deali.homework9.activity;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jaeger.library.StatusBarUtil;

import cn.deali.homework9.MainApp;
import cn.deali.homework9.R;
import cn.deali.homework9.adapter.PlaylistAdapter;


public class PlaylistActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle("播放列表");
        StatusBarUtil.setColor(PlaylistActivity.this, getResources().getColor(android.R.color.holo_red_light), 0);//状态栏
        setContentView(R.layout.activity_playlist);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);  // 返回箭头

        RecyclerView recyclerView = findViewById(R.id.recyclerview);

        PlaylistAdapter playlistAdapter = new PlaylistAdapter(PlaylistActivity.this, MainApp.getInstance().getPlaylist());
        recyclerView.setAdapter(playlistAdapter);

        //设置layout manager，默认垂直分布
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(PlaylistActivity.this);
        recyclerView.setLayoutManager(linearLayoutManager);
    }

    @Override
    //点击actionBar返回
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish();
                return false;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}
